/*
 * 
 * 同城微信小程序
 * author: hb
 * 技术支持微信号：wxid_i8yk4fp0uep322
 * 开源协议：MIT
 * Copyright (c) 2018 https://www.tczhb.club All rights reserved.
 */

import config from 'config.js'
var app = getApp();

var domain = config.getDomain;
var appdomain = config.getAppDomain;
var pageCount = app.globalData.page_size;
var categoriesID = 'all';
var HOST_APP_URI = appdomain + '/api/';
   
module.exports = {
  //获取配置信息
  getConfig: function (){
    return HOST_APP_URI + 'home/index/getConfig';
  },
  // 获取文章列表数据
  getPosts: function (obj) {
    var url = HOST_APP_URI + 'portal/articles?order=-published_time&limit=' + pageCount +'&page=' + obj.page;
    if (obj.categories != 0) {
      url += '&category_id=' + obj.categories;
    }
    if (obj.search != '') {
      url += '&keyword=' + encodeURIComponent(obj.search);
    } 
    if (obj.author && obj.author != '') {
      url += '&author=' + obj.author;
    }  
    if (obj.categories != 0) {
      url += '&categories=' + obj.categories;
    }
    return url;
  },
  //获取幻灯片
  getSwiperPosts: function () {
    return HOST_APP_URI + 'home/slides/read';
  },
  // 获取内容页数据
  getPostByID: function (id) {
    return HOST_APP_URI + 'portal/articles/' + id;
  },
  //获取分类列表
  getCategories: function (is_menu) {
    var url ='';
    if (categoriesID =='all'){
      if(is_menu){
        var c_count = 10;
        url = HOST_APP_URI + '/portal/categories?menu=' + c_count;
      }else{
        url = HOST_APP_URI + '/portal/categories';          
      }
    }
    else
    {
      url = HOST_APP_URI + '/portal/categories?id=' + categoriesID;
    }
    return url;
  },
  //获取指定的分类信息
  getCategoryById: function (id) {
    var url = HOST_APP_URI + '/portal/categories?id=' + id;
    return url;
  },
  //获取拼车分类列表
  getCarCategories: function () {
    var url = HOST_APP_URI + 'portal/carpoolCategries';
    return url;
  },
  //获取拼车信息
  getCarpoolList: function (){
    var url = HOST_APP_URI + '/portal/carpool';
    return url;    
  },
  //获取某文章评论
  getComments: function (obj) {
    var url = HOST_APP_URI + 'user/comments?page=' + obj.page + '&limit=100&object_id=' + obj.postID + '&table_name=portal_post';
    if(obj.pid){
      url += '&parent_id=' +obj.pid;
    }
    return url;
  },
  //获取回复
  getChildrenComments: function () {
    return HOST_APP_URI + 'user/replys/my';
  },
  //提交微信评论
  postWeixinComment: function () {
    return HOST_APP_URI + 'user/comments';
  }, 
  //获取我的微信评论
  getWeixinComment: function () {
      return HOST_APP_URI + 'user/comments/my'
  },
  //获取用户openid
  getOpenidUrl(id) {
    var url = HOST_APP_URI + '/wxapp/public/login';
    return url;
  },
  //点赞
  postLikeUrl() {
    var url = HOST_APP_URI + 'portal/articles/doLike';
    return url;
  },
  //判断当前用户是否点赞
  postIsLikeUrl() {
    var url = HOST_APP_URI + 'portal/articles/isLike';
    return url;
  },
  //发布信息
  creatPost(){
    return HOST_APP_URI + 'portal/articles/save';
  },
  //上传图片
  uploadPic(){
    return HOST_APP_URI + 'user/upload';
  },
  //删除信息
  deletePost(){
    return HOST_APP_URI + 'portal/Articles/delete';
  },
  //发布拼车信息
  createCarPool(){
    var url = HOST_APP_URI + 'portal/carpool/save';
    return url;
  },
  //签到
  signInPost(){
    return HOST_URI_WATCH_LIFE_JSON + 'weixin/signin';
  },
  //判断是否已签到
  isSignGet(){
    return HOST_URI_WATCH_LIFE_JSON + 'weixin/issignin';
  }
};